//
//  KFDStringConcatenator.m
//  KFD
//
//  Created by JIRENTIANXIANG on 6/5/15.
//  Copyright (c) 2015 KFD. All rights reserved.
//

#import "KFDStringConcatenator.h"

@interface KFDStringConcatenator ()

@property (copy,nonatomic) NSString* separator;

@end

@implementation KFDStringConcatenator

+(instancetype)concatenatorWithSeparator:(NSString*)separator
{
    KFDStringConcatenator* concatenator=[[KFDStringConcatenator alloc] initWithSeparator:separator];
    return concatenator;
}

-(instancetype)initWithSeparator:(NSString *)separator
{
    if (self=[super init]) {
        self.separator=separator;
        self.content=[[NSMutableString alloc] init];
    }
    return self;
}

-(instancetype)appendString:(NSString *)string
{
    [self.content appendFormat:@"%@%@",string,self.separator];
    return self;
}

-(NSString*)close
{
    NSString* content=[self.content stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:self.separator]];
    self.content=[NSMutableString string];
    return content;
}

-(NSString*)concatenateStringsInArray:(NSArray *)array
{
    for (NSString* string in array) {
        [self appendString:string];
    }
    return [self close];
}


@end
